<template>
  <el-drawer :title="title" :visible.sync="visible" direction="rtl" size="350px" @close="handleClose">
    <el-form ref="usageForm" label-position="top" label-width="80px" :model="form" :rules="rules">
      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="钉钉使用情况" prop="isUseDd">
            <select-dict-tag v-model="form.isUseDd" dict-code="crm_dingding" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="主管理员" prop="admin">
            <el-input v-model="form.admin" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="使用人数" prop="usersNum">
            <el-input-number v-model="form.usersNum" controls-position="right" :min="1" style="width:100%" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="私海情况" prop="shSituation">
            <select-dict-tag v-model="form.shSituation" dict-code="crm_sh_situation" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="认证情况" prop="certification">
            <select-dict-tag v-model="form.certification" dict-code="crm_authention_situation" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="成熟度" prop="maturity">
            <select-dict-tag v-model="form.maturity" dict-code="crm_maturity" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="钉钉指数" prop="ddIndex">
            <el-input-number v-model="form.ddIndex" controls-position="right" :min="1" style="width:100%" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" :rows="4" placeholder="请输入" type="textarea" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="el-drawer__footer">
      <el-button @click="handleClose">关 闭</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-drawer>
</template>

<script>
export default {
  name: 'InfomationDrawer',
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      title: '',
      visible: this.show,
      loading: false,
      form: {},
      rules: {
        isUseDd: [
          { required: true, message: '钉钉使用情况不能为空', trigger: 'blur' }
        ],
        admin: [
          { required: true, message: '主管理员不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    show: {
      immediate: true,
      handler(val) {
        this.visible = this.show
      }
    }
  },
  methods: {
    add() {
      this.title = '新增'
    },
    edit(row) {
      this.title = '编辑'
      this.$nextTick(() => {
        this.form = Object.assign({}, row)
      })
    },
    submitForm() {
      this.$refs.usageForm.validate((valid) => {
        if (valid) {
          this.handleClose()
        }
      })
    },
    reset() {
      this.form = {
        isUseDd: undefined,
        admin: undefined,
        usersNum: 1,
        shSituation: undefined,
        certification: undefined,
        maturity: undefined,
        ddIndex: 1,
        remark: undefined
      }
      this.resetForm('usageForm')
    },
    handleClose() {
      this.reset()
      this.$emit('update:show', false)
    }
  }
}
</script>
